import Promise from '../libs/promise.js'
import { baseURI, debug } from 'config.js'


module.exports.send = (url, data) => {
  // wx.showToast({
  //   title: '请求中...',
  //   icon: 'loading',
  //   duration: 10000
  // })

  return new Promise((resolve, reject) => {
    wx.request({
      url: baseURI + url,
      data: data,
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        resolve(res.data)
      },
      fail(err) {
        reject(new Error(err))
      },
      complete(res) {
        if (debug) {
          console.log({
            url: baseURI + url,
            sendData: data,
            resdata: res
          });
        }
        //wx.hideToast()
      }
    })
  })
}
